﻿using System.Collections.Generic;

namespace Epitech.Krisk.Xna.UI.Game.InGame.Gameplay
{
    public class SuitCard
    {
        public bool IsValid { get; private set; }
        public int ArmyWon { get; set; }

        public SuitCard(List<ClickableCard> cards)
        {
            IsValid = false;
            if (cards.Count == 3)
            {
                if (cards[0].TerritoryCard.CardType == CardType.Soldier
                    && cards[1].TerritoryCard.CardType == CardType.Soldier
                    && cards[2].TerritoryCard.CardType == CardType.Soldier)
                {
                    IsValid = true;
                    ArmyWon = 6;
                }
                if (cards[0].TerritoryCard.CardType == CardType.Tank
                    && cards[1].TerritoryCard.CardType == CardType.Tank
                    && cards[2].TerritoryCard.CardType == CardType.Tank)
                {
                    IsValid = true;
                    ArmyWon = 8;
                }
                if (cards[0].TerritoryCard.CardType == CardType.Warplane
                    && cards[1].TerritoryCard.CardType == CardType.Warplane
                    && cards[2].TerritoryCard.CardType == CardType.Warplane)
                {
                    IsValid = true;
                    ArmyWon = 4;
                }
                if (cards[0].TerritoryCard.CardType != cards[1].TerritoryCard.CardType
                    && cards[1].TerritoryCard.CardType != cards[2].TerritoryCard.CardType
                    && cards[2].TerritoryCard.CardType != cards[0].TerritoryCard.CardType
                    && cards[0].TerritoryCard.CardType != CardType.Joker
                    && cards[1].TerritoryCard.CardType != CardType.Joker
                    && cards[2].TerritoryCard.CardType != CardType.Joker)
                {
                    IsValid = true;
                    ArmyWon = 10;
                }
                if (!IsValid)
                {
                    int i = 0;
                    bool ok = false;
                    foreach (var clickableCard in cards)
                    {
                        if (clickableCard.TerritoryCard.CardType == CardType.Joker)
                        {
                            ok = true;
                            break;
                        }
                        i++;
                    }
                    if (ok)
                    {
                        bool tmp = false;
                        switch (i)
                        {
                            case 0:
                                if (cards[1].TerritoryCard.CardType == cards[2].TerritoryCard.CardType)
                                    tmp = true;
                                break;
                            case 1:
                                if (cards[0].TerritoryCard.CardType == cards[2].TerritoryCard.CardType)
                                    tmp = true;
                                break;
                            case 2:
                                if (cards[1].TerritoryCard.CardType == cards[0].TerritoryCard.CardType)
                                    tmp = true;
                                break;
                        }
                        if (tmp)
                        {
                            IsValid = true;
                            ArmyWon = 12;
                        }
                    }
                }
            }
        }
    }
}
